/*  ------------------------------------------------------------------------  */
/*  Paper        : Does Stakeholder Outrage Determine Executive Pay?          */
/*  Program      : a01-05-boardex.do                                          */
/*  Description  : BoardEx variables                                          */
/*  ------------------------------------------------------------------------  */

/*  ------------------------------------------------------------------------  */
//  Import BoardEx dataset

foreach bname in ///
	na_wrds_company_dir_names ///
	na_wrds_company_names ///
	na_wrds_company_profile ///
	na_company_profile_stocks ///
	na_wrds_company_director_names ///
	na_wrds_org_summary {

import sas using "$boardex/`bname'.sas7bdat", clear
	// br
	rename *, lower
	drop if missing(isin)
	drop if missing(boardid)
	keep isin boardid
	duplicates drop *, force
	save "$temp112/`bname'.dta", replace
}

clear

#delimit ;
append using 
"$temp112/na_wrds_company_dir_names.dta"
"$temp112/na_wrds_company_names.dta"
"$temp112/na_wrds_company_profile.dta"
"$temp112/na_company_profile_stocks.dta"
"$temp112/na_wrds_company_director_names.dta"
"$temp112/na_wrds_org_summary.dta", generate(_append)
; #delimit cr

tab _append
drop _append
duplicates drop isin boardid, force

gen ncusip = substr(isin,3,8)
drop isin
duplicates drop ncusip boardid, force


save "$temp112/ncusip_boardid.dta", replace

/*  ------------------------------------------------------------------------  */
//  BoardEx employment dataset

#delimit ;
import delimited "$datapath/na_dir_profile_emp.csv", case(preserve)
		stringcols(1 2 3 4 5 6 7 12 13) numericcols(8 9 10 11) clear 
; #delimit cr

drop FulltextDescription ClientDirectorID ClientCompanyID
format RowType DirectorName CompanyName RoleName %25s

keep if lower(BrdPosition) !="no"
tab BrdPosition
drop BrdPosition
drop if DateStartRole=="N" | DateEndRole=="N"
replace DateEndRole="20251231" if DateEndRole=="C"

//  Change dates from string to date format
foreach var of varlist DateStartRole DateEndRole {
gen long _`var' = date(`var', "YMD") 
order _`var', after(`var')
drop `var'
rename _`var' `var'
format `var' %tdCCYY-NN-DD
}

by CompanyID DirectorID, sort: egen DirStart = min(DateStartRole)
format DirStart %tdCCYY-NN-DD
rename CompanyID boardid

save "$temp112/na_dir_profile_emp.dta", replace

/*  -|----------------------------------------------------------------------  */
/*  ||  ---    Program end: a01-05-boardex.do                                 */
/*  -|  ---    Attila Balogh    --------------------------------------------  */